package com.authsphere.security.token.common;

import org.springframework.security.core.Authentication;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/12 09:27
 **/
public interface TokenStore {

    /**
     * Read the authentication stored under the specified token value.
     *
     * @param token The token value under which the authentication is stored.
     * @return The authentication, or null if none.
     */
    Authentication readAuthentication(String token);


    /**
     * Store an access token.
     * @param token The token to store.
     * @param authentication The authentication associated with the token.
     */
    void storeAccessToken(AccessToken token, Authentication authentication);

    /**
     * Read the authentication stored under the specified token value.
     * @param token The token value under which the authentication is stored.
     * @return The authentication, or null if none.
     */
    Authentication readAuthentication(AccessToken token);

    /**
     * Read an access token from the store.
     * @param tokenValue The token value.
     * @return The access token to read.
     */
    AccessToken readAccessToken(String tokenValue);

    /**
     * Remove an access token from the store.
     *
     * @param token The token to remove from the store.
     */
    void removeAccessToken(AccessToken token);

    /**
     * Remove an access token from the store.
     * @param tokenValue The token to remove from the store.
     */
    void removeAccessToken(String tokenValue);

    /**
     * Retrieve an access token stored against the provided authentication key, if it exists.
     *
     * @param authentication the authentication key for the access token
     *
     * @return the access token or null if there was none
     */
    AccessToken getAccessToken(Authentication authentication);
}
